package com.cskaoyan.controller;

import com.cskaoyan.bo.*;
import com.cskaoyan.service.GoodsService;
import com.cskaoyan.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GoodsController {

    @Autowired
    GoodsService goodsService;

    //商品列表
    @RequestMapping("admin/goods/list")
    public BaseRespVo goodsList(Integer page, Integer limit,String goodsSn,String name, String sort, String order){
        //模糊查询
        if ((goodsSn != null && goodsSn != "") || (name != null && name != "")) {
            GoodsListVo goodsListVo = goodsService.queryGoodList(page, limit, goodsSn, name, sort, order);
            return BaseRespVo.ok(goodsListVo);
        }
       GoodsListVo goodsListVo = goodsService.goodsList(page,limit,goodsSn,name,sort,order);
       return BaseRespVo.ok(goodsListVo);
    }
    //商品上架
    @RequestMapping("admin/goods/create")
    public BaseRespVo addCreate(@RequestBody CreateBo createBo){
      int ant = goodsService.addCreate(createBo);
        String s = "aa";
        return BaseRespVo.ok();
    }
    //商品详情参数回显
    @RequestMapping("admin/goods/catAndBrand")
    public BaseRespVo catAndBrand(){
        GoodsCatAndBrandVo goodsCatAndBrandVoList = goodsService.catAndBrand();
       return BaseRespVo.ok(goodsCatAndBrandVoList);
    }
    //删除商品
    @RequestMapping("admin/goods/delete")
    public BaseRespVo deleteGoods(@RequestBody DeleteGoods deleteGoods){
        int id = deleteGoods.getId();
        int ant = goodsService.deleteGoods(id);
        return BaseRespVo.ok();
    }
    //更新商品
    @RequestMapping("admin/goods/update")
    public BaseRespVo updateGoods(@RequestBody UpdateGoods updateGoods){
        int ant = goodsService.updateGoods(updateGoods);
        return BaseRespVo.ok();
    }
    //显示商品详情
    @RequestMapping("admin/goods/detail")
    public BaseRespVo detailGoods(Integer id){
        DetailGoodsVo detailGoodsVo = goodsService.detailGoods(id);
       return BaseRespVo.ok(detailGoodsVo);
    }
}
